package cn.miju.wechatpay.response;

import cn.miju.wechatpay.content.CodeMessage;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

import java.io.Serializable;

/**
 * <pre>
 *
 * 文件名 :  BaseResp
 * 创建时间 : 2023年03月13日 10:34
 * 文件描述 : 无
 *
 * </pre>
 *
 * @author Huzb
 * @version 1.0.0
 */
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
public class WechatpayBaseResp implements Serializable {
    private static final long serialVersionUID = 1L;

    /**
     * 接口返回码
     */
    private Integer code;
    /**
     * 接口返回信息
     */
    private String msg;

    public static WechatpayBaseResp builder(CodeMessage codeMessage, WechatpayBaseResp... source) {
        WechatpayBaseResp wechatpayBaseResp = null;
        if (null != source && source.length > 0) {
            wechatpayBaseResp = source[0];
        } else {
            wechatpayBaseResp = new WechatpayBaseResp();
        }
        wechatpayBaseResp.setCode(codeMessage.getCode());
        wechatpayBaseResp.setMsg(codeMessage.getMsg());
        return wechatpayBaseResp;
    }

    public boolean isSuccess() {
        return CodeMessage.SUCCESS.getCode().equals(code);
    }
}
